package com.wjy.common.bean.query;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Date 2018/10/1
 * @Author ybxxszl
 * @Desc 查询
 **/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class QueryBean {

    private Integer pageCurrent; // 当前页码
    private Integer pageSize; // 每页条数
    private Integer pageTotal; // 总页数
    private Integer itemBegin; // 起始条索引
    private Integer itemEnd; // 结束条索引
    private Integer itemTotal; // 总条数
    private String searchContent; // 搜索内容

    public QueryBean(Integer pageCurrent, Integer pageSize) {
        super();
        this.pageCurrent = pageCurrent;
        this.pageSize = pageSize;
    }

    public QueryBean(Integer pageCurrent, Integer pageSize, String searchContent) {
        super();
        this.pageCurrent = pageCurrent;
        this.pageSize = pageSize;
        this.searchContent = searchContent;
    }

    // 默认分页的每页条数
    public Integer getPageSizeORDefault() {
        if (getPageSize() == null) {
            setPageSize(10);
        }
        return getPageSize();
    }

    // 计算总页数
    public Integer getCalculatePageTotal() {
        int total = getItemTotal() / getPageSize();
        if (getItemTotal() % getPageSize() != 0) {
            total++;
        }
        return total;
    }

    // 计算起始条索引
    public Integer getCalculateItemBegin() {
        return (getPageCurrent() - 1) * getPageSize();
    }

    // 计算结束条索引
    public Integer getCalculateItemEnd() {
        return getPageCurrent() * getPageSize();
    }

}
